﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;
using System.Data;

namespace WebUI.Controls
{
    public partial class RefundLookup : BaseEditControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                Utilities.LoadDropDownList(ddlBrand, Brands.LoadAllActiveBrands().DefaultView, Brands.ColumnNames.BrandName, Brands.ColumnNames.ID);
            }
        }

        public delegate void AddProduct(object sender, ListItemEventArgs e);
        AddProduct onAddProduct;

        public AddProduct OnAddProduct
        {
            get { return onAddProduct; }
            set { onAddProduct = value; }
        }

        public delegate void AddIMEI(object sender, ListItemEventArgs e);
        AddIMEI onAddIMEI;

        public AddIMEI OnAddIMEI
        {
            get { return onAddIMEI; }
            set { onAddIMEI = value; }
        }

        protected void btnAddIMEI_OnClick(object sender, EventArgs e)
        {
            if (onAddIMEI != null)
            {
                ListItemEventArgs arg = new ListItemEventArgs();
                arg.Data = new System.Collections.Hashtable();
                arg.Data["IMEI"] = txtIMEI.Text;
                arg.Data["Price"] = 0 - decimal.Parse(txtPrice.Text);
                arg.Data["ModelID"] = int.Parse(ddlModel.SelectedValue);
                arg.Data["ModelName"] = ddlBrand.SelectedItem.Text + " " + ddlModel.SelectedItem.Text;
                onAddIMEI(this, arg);
                txtIMEI.Text = "";
                txtPrice.Text = "0";
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page), Guid.NewGuid().ToString(), String.Format("focusIMEI();", 1), true);
            }
        }

        protected void ddlBrand_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlBrand.SelectedIndex > 0)
            {
                Utilities.LoadDropDownList(ddlModel, RepairModels.GetModelsByBrandID(int.Parse(ddlBrand.SelectedValue)).DefaultView, RepairModels.ColumnNames.ModelName, RepairModels.ColumnNames.ID);
            }
        }

    }
}